package test;

public class maxSubSum1 {
    public static void main(String[] args) {
        int[] a = {-2, 4, -3, 5, 7, -1, 8, 1};
        int i = maxSub(a);
        System.out.println(i);
    }

    public static int maxSub(int[] a) {
        int maxsum = 0;
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length; j++) {
                int thisSum = 0;
                for (int k = i; k <= j; k++)
                    thisSum += a[k];

                if (thisSum > maxsum)
                    maxsum = thisSum;

            }
        }
        return maxsum;
    }
}
